<%@page import="com.railway.files.model.FilesPhotoColumns"%>
<%@ page contentType="text/html;charset=UTF-8"%>
<%@ include file="/commons/taglibs.jsp"%>
<html>
	<head>
		<%@ include file="/commons/listcssjs.jsp"%>
		<title><%=FilesPhotoColumns.TABLE_ALIAS%> 维护</title>
		<script type="text/javascript"> 	
			
		 $(document).ready(function() { 
	      
	       $.get("${ctx}/news/Category/getPermitinfoByCatId.do", {
	           Action:"get",catId:"PHOTO"}, function (data, textStatus){	                                
	         
	            // 查询三种人
	              var jsonData = eval("["+data+"]");     
	            
                  var totalsize = jsonData[0].total;
                  var lidata = jsonData[0].rows;
             		  if( totalsize > 0){
             		    var r = 0 ;
          		        var b = 0 ;
       			    	for(var k = 0 ; k < totalsize; k++){          			       	          		
          			    var state =lidata[k].state;
          		
          			      if(state == 'C'){   
          			         if(r ==0){
          			        	 form1.checkerid.value = '';     
          			        	 form1.checker.value = ''; 
          			             r = 1;
          			         }			       
          			         form1.checkerid.value += lidata[k].userid+",";
          			       //  form1.checker.value += lidata[k].username+",";
          			      }else if(state == 'M'){
          			         if(b == 0 ){
          			            form1.maintainerid.value= '';
          			            form1.maintainer.value = '';
          			                  b = 1;
          			         }
          			
          			         form1.maintainerid.value += lidata[k].userid+",";
          			     //    form1.maintainer.value += lidata[k].username+",";
          			      }
          		       }          		    
               		  		 
        	          }  
                 
	       });		
	     }); 
		 function smtform(){
	    	form1.action="${ctx}/news/Category/save.do";
	    	form1.method= "post";	    	
		    form1.submit();
		 }
		 function openDeptUserList(type){ 
		      	          
	        var width = 800;
            var height =350;
            var url='${ctx}/system/SysUser/showDeptUserList.do?catId=PHOTO&userTypes='+type; //要打开的窗口   
            var returnVal =  window.showModalDialog(url, window.document, "dialogWidth="+width+"px;dialogHeight="+height+"px;status:0;scroll:no");   
            if(returnVal == undefined) {           
          	   return;           
            }
   
            if(type == 'M'){
                      form1.maintainerid.value = returnVal[0];
                 //     form1.maintainer.value = returnVal[1];
            }else if(type == 'C'){
                      form1.checkerid.value = returnVal[0];
                     // form1.checker.value = returnVal[1];
            }else if(type =='V'){
                      form1.visitorid.value = returnVal[0];
               		 // form1.visitor.value = returnVal[1];
           
            }
             
 		  }
 		  </script>
	</head>
	<body>
		<div style="width: 1000px; padding: 0px;">
			<form id="form1" name="form1"
				action="${ctx}/files/Files/listAjaxManage.do?fileTypes=PHOTO"
				method="post" style="display: inline;">
				<input type="hidden" id="pageNumber" name="pageNumber" value="1" />
				<input type="hidden" id="pageSize" name="pageSize" value="10" />
				<c:if test="${sessionScope.username=='admin'}"> 
				<div class="queryPanel">
					<fieldset>
						<legend>
							搜索
						</legend>
						<table>
							<tr>
								<td class="tdLabel"><%=FilesPhotoColumns.ALIAS_NAMES%></td>
								<td>
									<input value="" id="names" name="names" maxlength="200"
										class="" />
								</td>
								<td class="tdLabel"><%=FilesPhotoColumns.ALIAS_MEMO%></td>
								<td>
									<input value="" id="memo" name="memo" maxlength="500" class="" />
								</td>
							</tr>
							<tr>
								<td class="tdLabel">
									维护负责人
								</td>
								<td>
									<input readonly value="" id="maintainer"
										name="maintainer" maxlength="200"
										onclick="javascript:openDeptUserList('M');" />

									<input type="hidden" name="maintainerid" />
								<td class="tdLabel">
									审核人
								</td>
								<td>
									<input readonly value="" id="checker" name="checker"
										maxlength="200" onclick="javascript:openDeptUserList('C');" />
				
									<input type="hidden" name="checkerid" />
									<input type="hidden" name="fileTypes" value="PHOTO" />
								</td>
							</tr>
						</table>
					</fieldset>
					<div class="handleControl">
						<input type="button" class="stdButton" style="width: 80px"
							value="保存" onclick="javascript:smtform();" />
						<input type="submit" class="stdButton" style="width: 80px"
							value="查询" />
						<div>
						</div>
						</c:if>
						<br></br>
						<div>
							<table id="userDataGrid"></table>

						</div>
			</form>
		</div>
	</body>
	<script type="text/javascript">
/**用于回调*/
	 function v_deleteItems(result){
			if (result){
				var rows = $('#userDataGrid').datagrid('getSelections');
				var ids = [];
				if(rows!=null&&rows.length>0){
					$.each(rows,function(i,n){ids.push(n.id)
					});
					$.post( "${ctx}/files/Files/delete.do?fileTypes=PHOTO", {"items":ids.join(',')}, 
							function(data){
								$.messager.alert('提示','删除成功','info');
								$('#form1').submit();
							}
					);
				}else{
					$.message.alert("请选择后进行删除操作！","warning");
				}
			}
		}
		var option = {
				title:'<%=FilesPhotoColumns.TABLE_ALIAS%>',
				iconCls:'icon-save',
				width:1000,
				height:500,
				nowrap: false,
				striped: true,
				collapsible:true,
				pageSize:20,
				url: "${ctx}/files/Files/listAjaxManage.do?fileTypes=PHOTO",                                                       
				remoteSort: false,
				idField:'id'																																																,
				columns:[[
							{field:'ck',checkbox:true}				
							,{field:'names',title:'<%=FilesPhotoColumns.ALIAS_NAMES%>',width:120,sortable:true}							
							,{field:'paths',title:'<%=FilesPhotoColumns.ALIAS_PATHS%>',width:120,sortable:true}
							,{field:'ctxpaths',title:'<%=FilesPhotoColumns.ALIAS_CTXPATHS%>',width:120,sortable:true}
								
							,{field:'fileTypes',title:'<%=FilesPhotoColumns.ALIAS_FILE_TYPES%>',width:120,sortable:true}				
							,{field:'memo',title:'<%=FilesPhotoColumns.ALIAS_MEMO%>',width:120,sortable:true}
							,{field:'creator',title:'<%=FilesPhotoColumns.ALIAS_CREATOR%>',width:120,sortable:true}
							,{field:'createTimeString',title:'<%=FilesPhotoColumns.ALIAS_CREATE_TIME%>',width:120,sortable:true}
				]],
				pagination:true,
				rownumbers:true,
				toolbar:[
				{
					id:'btnview',
					text:'查看',
					iconCls:'icon-view',
					handler:function(){
						var selected = $('#userDataGrid').datagrid('getSelected');
						if (selected){
							location.href="${ctx}/files/Files/show.do?fileTypes=PHOTO&id="+selected.id;
							return false;
						}
					}
				},'-',{
					id:'btnadd',
					text:'新增',
					iconCls:'icon-create',
					handler:function(){
							location.href="${ctx}/files/Files/create.do?fileTypes=PHOTO";
							return false;
					}
				},{
					id:'btnedit',
					text:'修改',
					iconCls:'icon-edit',
					handler:function(){
						var selected = $('#userDataGrid').datagrid('getSelected');
						if (selected){
							location.href="${ctx}/files/Files/edit.do?fileTypes=PHOTO&id="
							+selected.id;
							return false;
						}
					}
				},{
					id:'btndelete',
					text:'删除',
					iconCls:'icon-no',
					handler:function(){
					$.messager.confirm('确认', "确定要删除吗？" ,v_deleteItems);
					}
				}],
				onLoadSuccess: function(){
	            	function bindRowsEvent(){
		                var panel = $('#userDataGrid').datagrid('getPanel');
		                var rows = panel.find('tr[datagrid-row-index]');
		                rows.unbind('click').bind('click',function(e){
		                    return false;
		                });
		                rows.find('div.datagrid-cell-check input[type=checkbox]').unbind().bind('click', function(e){
		                    var index = $(this).parent().parent().parent().attr('datagrid-row-index');
		                    if ($(this).attr('checked')){
		                        $('#userDataGrid').datagrid('selectRow', index);
		                    } else {
		                        $('#userDataGrid').datagrid('unselectRow', index);
		                    }
		                    e.stopPropagation();
		                });
		            }
		            setTimeout(function(){
		                bindRowsEvent();
		            }, 10);    
	    		}
			}


		//重要$(document).ready(handler)
		$(function(){
			//设置form为ajax提交		
			$('#form1').form({
				success:function(data){
				data = eval('('+data+')');
				$('#userDataGrid').datagrid("loadData",data);
				}
			});
			//设置datagrid		
			$('#userDataGrid').datagrid(option);
			//设置底部的上一页和下一页
			var p = $('#userDataGrid').datagrid('getPager');
			if (p){
				$(p).pagination({
					onBeforeRefresh:function(){
				
					}
				});
				$(p).pagination({
					onSelectPage:function(pageNumber,pageSize){
						$("input[name='pageNumber']").val(pageNumber);
						$("input[name='pageSize']").val(pageSize);
						$('#form1').submit();
					}
				});
			}}
		); //end $(document).ready(handler)
		//以下这些方法放在这几是为了提供编写javascript参考用，可根据实际情况删除
		function resize(){
			$('#userDataGrid').datagrid('resize', {
				width:1100,
				height:400
			});
		}
		function getSelected(){
			var selected = $('#userDataGrid').datagrid('getSelected');
			if (selected){
				alert(selected.id);
			}
		}
		function getSelections(){
			var ids = [];
			var rows = $('#userDataGrid').datagrid('getSelections');
			for(var i=0;i<rows.length;i++){
				ids.push(rows[i].id);
			}
			alert(ids.join(':'));
		}
		function clearSelections(){
			$('#userDataGrid').datagrid('clearSelections');
		}
		function selectRow(){
			$('#userDataGrid').datagrid('selectRow',1); //行号从0开始
		}
		function selectRecord(){
			$('#userDataGrid').datagrid('selectRecord','1'); //'1'是id值
		}
		function unselectRow(){
			$('#userDataGrid').datagrid('unselectRow',1);//行号从0开始
		}
	</script>
</html>


